package com.leetcode.LC_MED;

public class LC437 {
    int num = 0;

    public int pathSum(TreeNode root, int sum) {

        if (root == null) {
            return 0;
        }
        dfs(root, sum);
        pathSum(root.left, sum);
        pathSum(root.right, sum);
        return num;
    }

    private void dfs(TreeNode root, int sum) {
        if (root == null) {
            return;
        }
        sum -= root.val;
        if (sum == 0) {//中途出现0，后续还可能为0
            num++;
            return;
        }
        dfs(root.left, sum);
        dfs(root.right, sum);
    }
}
